package com.originskyseed.platform.course.controller;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.originskyseed.platform.core.aspect.annotation.RequiredParams;
import com.originskyseed.platform.core.base.BaseController;
import com.originskyseed.platform.core.base.BaseLocaleResource;
import com.originskyseed.platform.core.base.BasePage;
import com.originskyseed.platform.core.base.BaseResponseBody;
import com.originskyseed.platform.core.common.code.CommonResponseCode;
import com.originskyseed.platform.course.i18n.CourseResponseMsg;
import com.originskyseed.platform.course.model.CourseRelateEvaluateReply;
import com.originskyseed.platform.course.service.ICourseRelateEvaluateReplyService;
import com.originskyseed.platform.course.vo.request.CourseRelateEvaluateReplyRequestVO;

/**
 * 课程评价关联回复表Controller类（OSI_COURSE_RELATE_EVALUATE_REPLY）
 * 
 * @author Tangwanghui
 */
@Controller
@RequestMapping("/courseRelateEvaluateReply")
@BaseLocaleResource(localeFileName = "i18n_course")
public class CourseRelateEvaluateReplyController extends BaseController {

	private static final Logger logger = LoggerFactory.getLogger(CourseRelateEvaluateReplyController.class);

	@DubboReference
	private ICourseRelateEvaluateReplyService courseRelateEvaluateReplyService;

	/**
	 * 分页查询
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/courseRelateEvaluateReplyList.json", method = RequestMethod.POST)
	@RequiredParams(names = { "pageNo", "pageSize" })
	public BaseResponseBody<BasePage<CourseRelateEvaluateReply>> courseRelateEvaluateReplyList(HttpServletRequest request) {
		BaseResponseBody<BasePage<CourseRelateEvaluateReply>> result = null;
		try {
			// 请求对象
			CourseRelateEvaluateReplyRequestVO requestVO = this.getParameterBean(CourseRelateEvaluateReplyRequestVO.class);

			// 分页查询
			BasePage<CourseRelateEvaluateReply> page = new BasePage<CourseRelateEvaluateReply>(requestVO.getPageNo(), requestVO.getPageSize());
			page = this.courseRelateEvaluateReplyService.selectListByPage(requestVO.toMap(), page);
			result = new BaseResponseBody<BasePage<CourseRelateEvaluateReply>>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_SUCCESS.getMsg()), page);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<BasePage<CourseRelateEvaluateReply>>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DATA_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 保存信息
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/courseRelateEvaluateReplySave.json", method = RequestMethod.POST)
	@RequiredParams(names = {})
	public BaseResponseBody<CourseRelateEvaluateReply> courseRelateEvaluateReplySave(HttpServletRequest request) {
		BaseResponseBody<CourseRelateEvaluateReply> result = null;
		try {
			// 请求对象
			CourseRelateEvaluateReply courseRelateEvaluateReply = this.getParameterBean(CourseRelateEvaluateReply.class);

			if (StringUtils.isNotBlank(courseRelateEvaluateReply.getId())) {
				this.courseRelateEvaluateReplyService.updateByPrimaryKey(courseRelateEvaluateReply);
			} else {
				this.courseRelateEvaluateReplyService.insertSelective(courseRelateEvaluateReply);
			}
			result = new BaseResponseBody<CourseRelateEvaluateReply>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_SUCCESS.getMsg()), courseRelateEvaluateReply);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<CourseRelateEvaluateReply>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.SAVE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

	/**
	 * 删除信息
	 * 
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/courseRelateEvaluateReplyDelete.json", method = RequestMethod.POST)
	@RequiredParams(names = { "ids" })
	public BaseResponseBody<Boolean> courseRelateEvaluateReplyDelete(HttpServletRequest request) {
		BaseResponseBody<Boolean> result = null;
		try {
			// 请求参数
			String[] ids = this.getParameterArray("ids", new String[] {});

			this.courseRelateEvaluateReplyService.deleteByPrimaryKeys(Arrays.asList(ids));
			result = new BaseResponseBody<Boolean>(true, CommonResponseCode.SUCCESS.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DELETE_SUCCESS.getMsg()), true);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			result = new BaseResponseBody<Boolean>(false, CommonResponseCode.ERROR.getCode(), this.getLocaleMessage(this.getClass(), CourseResponseMsg.DELETE_ERROR.getMsg()), e.getMessage(), null);
		}
		return result;
	}

}